import {instantiate, math, Node, Prefab} from 'cc';
import {CombinationHandler} from "db://assets/Scripts/MVC/Monster/CombinationHandler";
import {MonsterController} from "db://assets/Scripts/MVC/Monster/MonsterController";
import {MonsterType} from "db://assets/Scripts/MVC/Monster/MonsterType";
import {PoolManager} from "db://assets/Scripts/framework/PoolManager";

/**
 * 一个敌人策略
 */
export class OnePolicy implements CombinationHandler {

    /**
     * 一个敌人
     *
     * @param prefab 敌人预制体
     * @param parent 父节点
     */
    combination(prefab: Prefab, parent: Node): Node[] {
        // 创建敌人列表
        const monsterNodes: Node[] = [];

        // 创建敌人
        const monsterNode = PoolManager.getInstance().getNode(prefab, parent);
        // x坐标范围(-4,4)
        const x = math.randomRangeInt(-4, 5);
        // 设置位置
        monsterNode.setPosition(x, 0, -10);

        // 获取脚本
        const monsterController: MonsterController = monsterNode.getComponent(MonsterController);
        // 设置为超级战机
        monsterController.uiState.type = MonsterType.SUPER;

        // 添加至列表
        monsterNodes.push(monsterNode);
        // 返回列表
        return monsterNodes;
    }
}